home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Sound Cards
/
Programming Sound Cards.iso
/
sound_89
/
vocplay.doc
< prev
Wrap
Text File
|
1995-01-01
|
4KB
|
96 lines
─ Area: 80x86 Assembler ──────────────────────────────────────────────────────
Msg#: 34 Date: 01-18-93 16:00
From: Phil Inch Network: GT Power
To: Edward Schlunder
Subj: Playing VOCs on PC's Internal Speaker.
──────────────────────────────────────────────────────────────────────────────
OK, now I'm not saying this is the "best" or "correct" way to play these
files (see note below) but it does work. Instead of posting actual code
I'll just describe the method, so you and other readers can use their
programming language of choice!
FIRST: Open the VOC file and skip the first 26 bytes. This is header
information among which the only useful info is the speed at which the VOC
was recorded. For this message I won't go into how to do timing correctly.
NOW, set a "timing" variable. This variable will be used as a delay counter
later on. It's just an integer, and in assembler I've found that 256 works
well. (This will make sense later).
OK, for EACH BYTE, follow this process:
1) If the byte = 127, go to step 5
2) Push the speaker "out". In ASM, this is done by:
IN AL,61h
OR AL,3h
OUT 61h,AL
3) Delay for ( BYTE / 256 ) * TIMING VARIABLE. This could be a FOR/NEXT
loop or whatever. In assembler, I use LOOPNZ
4) Pull the speaker back "in". In ASM:
IN AL,61h
AND AL,FCh
OUT 61h,AL
5) Delay for the remaining balance of TIMING VARIABLE.
6) Return to step 1 until the end of the file is encountered.
So what the hell is it doing? It's actually fairly simple. Steps 2-4 allow
you to "pulse" the speaker with a varying force. The amount of force is
determined by the length of the delay in step 3. In other words,
the shorter the delay, the less time the speaker has to move out before it's
pulled back in.
This should tell you straight away that the code in step 3 needs to be TIGHT.
I really feel that assembler is the only tool for this job, but I am happy
to be proved wrong. Personally I use assembler.
The basic trick is this; the bytes in a VOC file determine the waveform,
although it's important to note that VOC files can be "packed". I'll explain
this later. If you want to see what I mean, write a program to read the value
of each byte in the file and plot this byte on a graph...lo and behold, you
will see the waveform before your very eyes! 127 is the middle value, and
the waveform rises above and below this value.
So, if the byte is 1, the above makes this a very short (read:quiet) pulse.
If it's 255, it's a long (read:loud) pulse. Everything in between is
varying degrees from soft to loud, except for 127 which is considered to be
"silence".
You should now see that steps 3 and 5 "divide" the timing delay into a
"pulse" and "silence" part. Overall, however, you still end up delaying for
the total duration of the timing variable. Therefore, you should progress
through the file at an even rate!
Now, a few notes. First, it's desirable to load the file into memory first
as disk access *really* bogs the whole thing down. Second, if you want to
play them at the correct rate, you'll have to get into programming interrupts
because that's the only reliable way to do this. Third: packed VOC files may
not sound correct.
I am developing a program called VOC-IT, which will play VOCS as explained
above, and allow you to play them more quickly or slowly, and it will deal
with packed VOCS correctly. I will also be offering source code for a small
consideration. Got to have some return <grin>! I have already released
VOCHDR, which reads and displays the header information of one or more VOC
files in the current directory. Look out for it - I'm working under the name
"Imperial Software".
Regards
Phil
───────────────────────═══════════════════════════─────────────────────────
Again, my thanks go to Phil for giving out the information about how
his programs work, even if it means giving up the chance to get
registrations for his work. Phil is truly a great guy. Please support him,
don't go into competition!
- Edward T. Schlunder